
public class Leetcode997 {
    public static void main(String[] args) {
        System.out.println(findJudge(3, new int[][]{
                {1, 3},
                {2, 3}
        }));
    }

    public static int findJudge(int n, int[][] trust) {
        boolean[] sings = new boolean[n + 1];
        int[] trusts = new int[n + 1];

        for (int[] index : trust) {
            trusts[index[1]]++;
            sings[index[0]] = true;
        }

        int judge = -1;
        for (int i = 1; i < sings.length; i++) {
            if (!sings[i] && trusts[i] == n - 1) {
                judge = i;
            }
        }

        return judge;
    }
}
